/**  
 * Copyrights@2006, Tianyuan DIC Information Co.,Ltd.
 * 文件名:    TMallRetTask.java  
 * 描述:   
 * 作者:     kaiyang
 * 版本:    1.0  
 * 创建时间:   2015年6月12日 下午3:09:33  
 *  
 * 修改历史:  
 * 日期                          作者           版本         描述  
 * ------------------------------------------------------------------  
 * 2015年6月12日      kaiyang      1.0        1.0 Version  
 */ 
package com.hp.bon.sgw.wh.channel.handler;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**  
 * @ClassName: TMallRetTask   
 * @Description: TODO  
 * @author: kaiyang  
 * @date:2015年6月12日 下午3:09:33     
 */
public class TMallRetTask implements Runnable{
	private final static Logger _log = LoggerFactory.getLogger(TMallRetTask.class);
    private String retUrl;
	private Map<String,String> paraMap;
	public TMallRetTask(String retUrl,Map<String,String> paraMap)
	{
		this.retUrl = retUrl;
		this.paraMap = paraMap;
	}
	
	@Override
	public void run() {
		List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
		for(Entry<String,String> entry:paraMap.entrySet())
		{
			BasicNameValuePair pair = new BasicNameValuePair(entry.getKey(),entry.getValue());
			params.add(pair);
		}
		String getParam = URLEncodedUtils.format(params,"GBK");
		_log.info("request param:{}",getParam);
		_log.info("retUrl:"+retUrl);
		HttpGet httpGet = new HttpGet(retUrl+"?"+getParam);
		try{
			HttpClient httpClient = new DefaultHttpClient();
			HttpResponse httpResponse = httpClient.execute(httpGet);
			_log.info("response http code = {}",httpResponse.getStatusLine().getStatusCode());
			_log.info("response Data = {}",EntityUtils.toString(httpResponse.getEntity(),"UTF-8"));
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
